﻿using System;
using System.Collections.Generic;

namespace RaisingStudio.SmallProgram.Library
{
    [SmallProgramType]
    public static class Stack
    {
        private static Dictionary<Primitive, Stack<Primitive>> _stackMap = new Dictionary<Primitive, Stack<Primitive>>();

        public static Primitive GetCount(Primitive stackName)
        {
            Stack<Primitive> stack;
            if (!_stackMap.TryGetValue(stackName, out stack))
            {
                stack = new Stack<Primitive>();
                _stackMap[stackName] = stack;
            }
            return stack.Count;
        }

        public static void PushValue(Primitive stackName, Primitive value)
        {
            Stack<Primitive> stack;
            if (!_stackMap.TryGetValue(stackName, out stack))
            {
                stack = new Stack<Primitive>();
                _stackMap[stackName] = stack;
            }
            stack.Push(value);
        }

        public static Primitive PopValue(Primitive stackName)
        {
            Stack<Primitive> stack;
            if (_stackMap.TryGetValue(stackName, out stack))
            {
                return stack.Pop();
            }
            return "";
        }
    }
}

